package com.suncnpap.base.common;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.suncnpap.reader.model.Reader;
import com.suncnpap.system.model.Admin;

public class GlobaUser {
	
	private static Map<String, Object[]> userMap=new HashMap<String, Object[]>();
	
	public static void setGlobaUser(String token, Admin admin) { 
		Object[] object = new Object[]{"admin",admin};
	    userMap.put(token, object);
	}
	
	public static void setGlobaReader(String token, Reader reader) { 
		Object[] object = new Object[]{"reader",reader};
	    userMap.put(token, object);
	}

	public static Map<String, Object[]> getUserMap() {
		return userMap;
	}
	
	public static Object[] getUser(String token){
		Object[] obj=GlobaUser.getUserMap().get(token);
		return obj;
	
	}
	
	public static void removeGlobaUser(String token){
		userMap.remove(token);
	}
	
	public static String getStrId(String token) {
		Object[] obj = getUser(token);
		if(obj!=null){
			if((obj[0]+"").equals("admin")){
				Admin user = (Admin) obj[1];
				return user==null?"":user.getStrId();
			}else{
				Reader reader = (Reader) obj[1];
				return reader==null?"":reader.getStrId();
			}
		}
		return "";
	}
	
	public static String getStrCname(String token) {
		Object[] obj = getUser(token);
		if(obj!=null){
			if((obj[0]+"").equals("admin")){
				Admin user = (Admin) obj[1];
				return user==null?"":user.getStrName();
			}else{
				Reader reader = (Reader) obj[1];
				return reader==null?"":reader.getStrName();
			}
		}
		return "";
	}
	
	/**
	 * 获取当前登录的SchoolId
	 * @return
	 */
	public static String getStrSchoolId(String token) {
		Object[] obj = getUser(token);
		if(obj!=null){
			if((obj[0]+"").equals("admin")){
				Admin user = (Admin) obj[1];
				return user==null?"":user.getStrSchoolId();
			}else{
				Reader reader = (Reader) obj[1];
				return reader==null?"":reader.getStrSchoolId();
			}
		}
		return "";
	}
}
